#include "util/thread.h"
#include "util/object.h"
#include <map>
#include <algorithm>


NS_UTIL_BEGIN

namespace Thread
{
	Logger& this_logger()
	{
		static Logger logger;
		static bool first = true;
		if(first)
		{
			first = false;

			ObjectPtrT<LoggerConsole> pLoggerConsole = new LoggerConsole();
			logger.SetData(pLoggerConsole);
			// Start daemon
			std::thread _daemon(__g_daemon_for_logger);
			daemon.swap(_daemon);
			daemon.detach();
			
		}else
		{
		}
		return logger;
	}

	Timer& this_timer()
	{
		static Timer timer;
		return timer;
	}

	void __g_daemon_for_logger()
	{
		// touch this_logger()
		while(1)
		{
			Logger& logger = this_logger();
			logger.refresh();
			sleep(__g_sleep_time);
		}
	}
}

NS_UTIL_END